package com.yourenbang.lingyun.transaction.web.controller.pay.klks;

import com.yourenbang.lingyun.core.base.interceptor.ExcludeInterceptor;
import com.yourenbang.lingyun.core.util.KLog;
import com.yourenbang.lingyun.core.util.http.HttpClientUtil;
import com.yourenbang.lingyun.transaction.web.domain.vo.pay.klks.PayEposNoticeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/transaction/push/klks/epos/")
public class EposPushController {

    private static final String baseUrl = "https://api2.kaolakuaishou.com";

    /**
     * 电签支付通知转发
     */
    @ExcludeInterceptor
    @RequestMapping(value = "/pay/notice", method = RequestMethod.POST)
    public PayEposNoticeVO payNotice(@RequestBody String param) {
        KLog.info("【电签支付通知转发】入参:{}", param);
        String url = baseUrl + "/pay/epos/payNotice";

        try {
            String result = HttpClientUtil.httpPostRequest(url, param);
            KLog.info("【电签支付通知转发】生产响应:{}, 入参:{}", result, param);
        } catch (Exception e) {
            KLog.error("【电签支付通知转发】异常:{}, 入参:{}", e.getMessage(), param, e);
        }

        KLog.info("【电签支付通知转发】入参:{}", param);
        return new PayEposNoticeVO();
    }

    /**
     * 电签手续费通知转发
     */
    @ExcludeInterceptor
    @RequestMapping(value = "/fee/notice", method = RequestMethod.POST)
    public PayEposNoticeVO feeNotice(@RequestBody String param) {
        KLog.info("【电签手续费通知转发】入参:{}", param);
        String url = baseUrl + "/pay/epos/feeNotice";

        try {
            String result = HttpClientUtil.httpPostRequest(url, param);
            KLog.info("【电签手续费通知转发】生产响应:{}, 入参:{}", result, param);
        } catch (Exception e) {
            KLog.error("【电签手续费通知转发】异常:{}, 入参:{}", e.getMessage(), param, e);
        }

        KLog.info("【电签手续费通知转发】入参:{}", param);
        return new PayEposNoticeVO();
    }

}
